require('cgi/util')
htmlfile = './file/my-app1/kongyiji.html'
textfile = './file/my-app1/kongyiji.txt'

html = File.read(htmlfile)

File.open(textfile, 'w') do |f|
  in_head = true
  html.each_line do |line|
    if in_head && /class="article-content raw"/ !~ line
      next
    else
      in_head = false
    end
    break if /class="article-footer"/ =~ line
    line.gsub!(/<[^>]+>/, '')
    line.lstrip!
    # esc_line = CGI.unescapeHTML(line)
    f.write(line)
  end
end